package br.ufmg.ubicomp.droidguide.application;

import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AdapterView.OnItemClickListener;
import br.ufmg.ubicomp.droidguide.R;
import br.ufmg.ubicomp.droidguide.common.DroidGuideConfigurationManager;
import br.ufmg.ubicomp.droidguide.utils.AndroidUtils;

public class ActivitiesMenuList extends ListActivity {

	List<String> infoItems = new ArrayList<String>();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//setContentView(R.layout.info);
		initListInfoServices();

		// Use an existing ListAdapter that will map an array
		// of strings to TextViews
		setListAdapter(new ArrayAdapter<String>(this,
				android.R.layout.simple_expandable_list_item_1, infoItems));

		getListView().setItemsCanFocus(true);
		getListView().setOnItemClickListener(new OnItemClickListener() {

			public void onItemClick(AdapterView<?> arg0, View view, int arg2,
					long id) {
				String info = getItem((int) id);
				//showAlert(id, info);
				showInfoView(info);
			}

		});
		getListView().setTextFilterEnabled(true);
	}

	private void initListInfoServices() {
		String[] meuArray = getResources().getStringArray(R.array.activities_menu);
		for (String s : meuArray) {
			infoItems.add(s);
		}
	}

	private String getItem(int id) {
		return infoItems.get(id);
	}

	private void showInfoView(String info) {
		if (info.equals("List all")) {
			DroidGuideConfigurationManager.getInstance().addData("actType", "getAll");
			AndroidUtils.startActivity(this, TouristActivities.class);
		} else if (info.equals("List recomended")) {
			DroidGuideConfigurationManager.getInstance().addData("actType","getRecomended");
			// start services list
			AndroidUtils.startActivity(this, TouristActivities.class);
		} else if (info.equals("List landmarks")) {
			AndroidUtils.startActivity(this, Web.class);
		} 
	}
	
}
